﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using DMU;
using MySql.Data.MySqlClient;
using System.Data.SqlClient;

namespace Gui.GuiPro
{
    public partial class frmChangPas : DevExpress.XtraEditors.XtraForm
    {
        public frmChangPas()
        {
            InitializeComponent();
        }

        help hp = new help();

        Service sv = new Service();
        private void frmChangPas_Load(object sender, EventArgs e)
        {
            txtUser.Text = Service.username;
        }

        private void btnChange_Click(object sender, EventArgs e)
        {
            if (txtOldPass.Text != Service.pass)
            {
                txtOldPass.Focus(); return;
            }
            if (!dxValidationProvider1.Validate())
            {
                txtNewPas.Focus();
                return;

            }
                try
                {
                    SqlParameter[] pr = new SqlParameter[2];
                    pr[0] = new SqlParameter("MaGV0", txtUser.Text);
                    pr[1] = new SqlParameter("MatKhau0", txtNewPas.Text);

                    if (sv.executeNonqueryStore("dmu_proLonginChangePass", pr))
                    {
                        hp.showMes("Thay đổi thành công !", -1); this.Close();
                    }
                }
                catch (Exception et)
                {
                    hp.showMes("Có lỗi khi thay đổi vui lòng thử lại !" + et.Message, 1);
                }

            
        }


        private void txtOldPass_Validating(object sender, CancelEventArgs e)
        {
            if (txtOldPass.Text != Service.pass)
                lblTB.Show();
            else
                lblTB.Hide();
        }
    }
}
